//商家信息
// const db = uniCloud.databaseForJQL({
// 	clientInfo: this.getClientInfo()
// });
const db = uniCloud.database();
const utils = require('quanzi-utils');
const cmd = db.command;
module.exports = {
	_before: async function() { // 通用预处理器
		this.params = this.getParams()[0];
		this.userInfo = await utils.getUsetInfo(this);
		this.dbJQL = uniCloud.databaseForJQL({
			clientInfo: this.getClientInfo()
		});
	},
	// 后台获取该用户商户信息
	async get() {
		return db.collection('mall-brand').where({
			user_id: this.userInfo.uid
		}).get();
	},
	// 后台用户添加商户信息
	async add() {

		let userData = {
			...this.params
		};
		let res = await this.dbJQL.collection("mall-brand").add(userData);
		return res;
	},
	// 后台用户修改商户信息
	async update() {
		let params = {
			...this.params
		};
		delete params._id
		return db.collection("mall-brand").doc(this.params._id).update(params);
	},
	//获取该商店店铺信息
	async getShopBrand(id) {
		return await db.collection('mall-brand').doc(id).get();
	}
}